package mh.demo.springboot.strategy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;

/**
 * 在 Spring Boot 中实现策略模式
 * 源自：https://mp.weixin.qq.com/s/O_hmIuXFOp_oQzB5rm_c9g
 */
@Service
public class FileParserService {

    private final FileParserFactory fileParserFactory;

    @Autowired
    public FileParserService(FileParserFactory fileParserFactory) {
        this.fileParserFactory = fileParserFactory;
    }

    public void parse(File file, String fileType) {
        FileParser fileParser = fileParserFactory.get(fileType);
        fileParser.parse(file);
    }

}
